package com.hksj.data.tdengine.controller;

import com.hksj.data.tdengine.operation.TDengineOperations;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.influxdb.dto.Point;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @author zengke
 * @version 1.0
 * @see TestController123
 * @since 2025/08/14 18:09
 */

@RestController
@RequestMapping("/testcontroller123")
@Api(tags = "tdengine数据存储")
public class TestController123 {

    @Autowired(required = false)
    private TDengineOperations tDengineOperations;

    @ApiOperation(value = "测试")
    @PostMapping("/test")
    public void test1(){

        Map<String,String> tags = new HashMap<>();
        tags.put("location", "us-midwest");
        tags.put("name", "zengke");

        Map<String, Object> values = new HashMap<>();
        values.put("temperature", 42.0);
        values.put("humidity", 42.0);
        values.put("id",12345L);
        values.put("rawValue","asadadsadsadsadadsa,asdasda");
        values.put("booleanValue", true);

        Point point = Point.measurement("test1").tag(tags).fields(values).time(System.currentTimeMillis(), TimeUnit.MILLISECONDS).build();

        tDengineOperations.forWrite().write(point);
    }
}
